package unitTest;

import com.mic.yzzn.plc.common.control.RMI.PLCCollector;
import com.mic.yzzn.plc.common.control.datastructure.PLCMission;
import com.mic.yzzn.plc.common.instructions.basic.PLCRequestInstruction;
import com.mic.yzzn.plc.core.control.datastructure.PLCStationConfig;

import java.rmi.Naming;
import java.util.ArrayList;

/**
 * Created by ASH on 16/5/17.
 */
public class ConfigRealTimeWriteTest implements Runnable
{
    public String threadName;
    public PLCStationConfig stationConfig;
    public ArrayList<PLCRequestInstruction> writeInstructions;

    @Override
    public void run()
    {
        if (stationConfig == null)
        {
            return;
        }

        PLCMission mission = new PLCMission(PLCMission.PLCMissionTypeWriteFireAndForget, PLCMission.PLCMISSION_PRIORITY_RTW_0);
        mission.setInstructions(writeInstructions);

        PLCCollector collector = null;
        try
        {
            collector = (PLCCollector) Naming.lookup(stationConfig.id());

            while (true)
            {
                System.out.println(threadName + ": " + collector.addRealtimeWriteMission(mission));
                System.out.println();
                Thread.sleep(stationConfig.getFlashTime() * 1000);
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
